//
//  ViewController.m
//  ZipDemo
//
//  Created by liaozhenming on 16/3/23.
//  Copyright © 2016年 liaozhenming. All rights reserved.
//

#import "ViewController.h"

#import "ZipArchive/ZipArchive.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self private_openZipFile];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Private methods

- (void)private_openZipFile {
    
    NSString *sourceFilePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @"20160323.zip"];
    NSString *targetFilePath = [NSHomeDirectory() stringByAppendingPathComponent: @"/Documents/20160323.zip"];
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath: targetFilePath]) {
        [fileManager removeItemAtPath: targetFilePath error: nil];
    }
    
    [fileManager copyItemAtPath: sourceFilePath toPath: targetFilePath error: nil];
    
    NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent: @"/Documents/20160323"];
    ZipArchive* zip = [[ZipArchive alloc] init];
    
    if( [zip UnzipOpenFile:targetFilePath] )
    {
        BOOL ret = [zip UnzipFileTo:filePath overWrite:YES];
        if( NO==ret )
        {
        }
        [zip UnzipCloseFile];
    }
}

@end
